
<!doctype html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="https://cdn.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.4/favicon.ico">
    <link rel="canonical" href="https://getbootstrap.com/docs/3.4/examples/dashboard/">

    <title>基于Django的气象数据采集和分析</title>

    <!-- Bootstrap core CSS -->
    <link href="https://cdn.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.4/dist/css/bootstrap.min.css" rel="stylesheet">

    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <link href="https://cdn.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.4/assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="https://cdn.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.4/examples/dashboard/dashboard.css" rel="stylesheet">

    <!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
    <!--[if lt IE 9]><script src="https://cdn.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.4/assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
    <script src="https://cdn.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.4/assets/js/ie-emulation-modes-warning.js"></script>

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>

  <body>

    <nav class="navbar navbar-inverse navbar-fixed-top">
      <div class="container-fluid">
        <div class="navbar-header">
          <a class="navbar-brand" href="#">基于Django的气象数据采集和分析</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
          <ul class="nav navbar-nav navbar-right">
            <li><a href="#">欢迎登陆</a></li>
            <li><a href="login.html">退出</a></li>
          </ul>
        </div>
      </div>
    </nav>

    <div class="container-fluid">
      <div class="row">
        <div class="col-sm-3 col-md-2 sidebar">
          <ul class="nav nav-sidebar">
            <li><a href="crawler.html">数据爬取</a></li>
            <li><a href="user.html">用户管理</a></li>
            <li><a href="city.html">城市分析</a></li>
            <li class="active"><a href="meteorology.html">气象分析</a></li>
            <li><a href="max_temperature.html">最高温度升序排行榜</a></li>
            <li><a href="max_temperature_desc.html">最高温度降序排行榜</a></li>
            <li><a href="min_temperature.html">最低温度升序排行榜</a></li>
            <li><a href="min_temperature_desc.html">最低温度降序排行榜</a></li>
          </ul>
        </div>
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
          <h1 class="page-header">气象分析</h1>
          <!-- 搜索框 -->
          <div class="panel-body">
              <form role="form" id="searchForm" class="form-inline">
                  <div class="form-group"> <input type="text"
                          class="form-control" id="publish_time" name="publish_time" placeholder="请输入日期">
                  </div>
                  <div class="form-group">
                   <select  id="week" class="form-control">
                       <option>全部星期</option>
                       <option>星期一</option>
                       <option>星期二</option>
                       <option>星期三</option>
                       <option>星期四</option>
                       <option>星期五</option>
                       <option>星期六</option>
                       <option>星期日</option>
                    </select>
                  </div>
                  <div class="form-group">
                   <select  id="weather" class="form-control">
                       <option>天气状况</option>
                       <option>小雨</option>
                       <option>多云</option>
                       <option>阴</option>
                       <option>晴</option>
                       <option>大雨</option>
                       <option>中雨</option>
                       <option>雷阵雨</option>
                       <option>阵雨</option>
                    </select>
                  </div>
                  <div class="form-group"> <input type="text"
                          class="form-control" id="city__name" name="city__name" placeholder="请输入城市名称">
                  </div>
                  <div class="form-group">
                      <button type="button" id="searchBtn" class="btn btn-default">开始搜索</button>
                  </div>
                  <div class="form-group">
                      <button type="button" id="lineBtn" class="btn btn-default">天气分析</button>
                  </div>
                  <div class="form-group">
                      <button type="button" id="windBtn" class="btn btn-default">风向分析</button>
                  </div>
              </form>
          </div>
          <table id="table"></table>
        </div>
      </div>
    </div>
    <!-- 操作模态框 -->
    <div class="modal fade" id="opDataxJobRowModal" tabindex="-1" role="dialog" >
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="exampleModalLabel">气象分析</h4>
          </div>
          <div id="loading" style="height: 400px;">
            <div id="container" style="height: 400%; width: 600%"></div>
          </div>
        </div>
      </div>
    </div>

    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js" integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ" crossorigin="anonymous"></script>
    <script>window.jQuery || document.write('<script src="https://cdn.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.4/assets/js/vendor/jquery.min.js"><\/script>')</script>
    <script src="https://cdn.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.4/dist/js/bootstrap.min.js"></script>
    <!-- Just to make our placeholder images work. Don't actually copy the next line! -->
    <script src="https://cdn.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.4/assets/js/vendor/holder.min.js"></script>
    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <script src="https://cdn.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.4/assets/js/ie10-viewport-bug-workaround.js"></script>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts@5/dist/echarts.min.js"></script>
    <script src="assets/js/table/bootstrap-table.js"></script>
    <script src="assets/js/table/bootstrap-table-zh-CN.js"></script>
    <script type="text/javascript">
      var message = '';
      var myChart='';
      var dom = document.getElementById("container");
      var xValue = [];
      var yValue = [];
      // 通用初始化模板
      function initEcharts(valueX, valueY){
          console.log(valueX)
          console.log(valueY)
          myChart = echarts.init(dom);
          var app = {};
          var option;
          option = {
              xAxis: {
                  type: 'category',
                  data: valueX
              },
              yAxis: {
                  type: 'value'
              },
              series: [{
                  data: valueY,
                  type: 'line'
              }],
              tooltip : {
                  trigger: 'axis',
                  axisPointer: {
                      type: 'cross',
                      label: {
                          backgroundColor: '#6a7985'
                      }
                  }
              }
          };

          if (option && typeof option === 'object') {
              myChart.setOption(option,true);
          }
      }
      // 初始化表格数据
      $(function(){
        init()
      });
      function init(){
        $('#table').bootstrapTable("showLoading");
        $.ajax({ 
          url: "http://127.0.0.1:8082/api/crawler/get_citydata_by_name_or_year/",
          method: "get",
          dataType: "json",
          success: function(rs){
            message = rs.results
            $('#table').bootstrapTable('load', message);
            $('#table').bootstrapTable('refresh');
            $('#table').bootstrapTable("hideLoading");
          },
        })
      };
      // 初始化表格
      $('#table').bootstrapTable({
        cache:false,
        clickToSelect:true,
        pageSize: 15,
        pageNumber: 1,
        pagination: true,
        columns: [{
          field: 'id',
            title: '编号'
          }, {
            field: 'publish_time',
            title: '日期'
          }, {
            field: 'week',
            title: '星期'
          }, {
            field: 'top_temperature',
            title: '最高温度(℃)'
          }, {
            field: 'low_temperature',
            title: '最低温度(℃)'
          }, {
            field: 'weather',
            title: '天气'
          }, {
            field: 'wind_direction',
            title: '风向'
          }, {
            field: 'city',
            title: '城市名称'
          }]
      });
      // 搜索
      $("#searchBtn").click(function() {
        var publish_time = $("#publish_time").val();
        var week = $("#week option:selected").val();
        var weather = $("#weather option:selected").val();
        var city__name = $("#city__name").val();
        if(week.includes("全部星期")){
          week = '';
        }
        if(weather.includes("天气状况")){
          weather = '';
        }
        $.ajax({
          type: "get",
          url: "http://127.0.0.1:8082/api/crawler/get_citydata_by_name_or_year/",
          cache: false,
          data: {
            publish_time : publish_time,
            week : week,
            weather : weather,
            city__name : city__name
          },
          success : function(res) {
            message = res.results
            $("#table").bootstrapTable('load', message);//主要是要这种写法
            $('#table').bootstrapTable('refresh');
          }
        });
      });
      // 折线图分析
      $("#lineBtn").click(function() {
        $("#opDataxJobRowModal").modal('toggle');
        var publish_time = $("#publish_time").val();
        var week = $("#week option:selected").val();
        var weather = $("#weather option:selected").val();
        var city__name = $("#city__name").val();
        if(week.includes("全部星期")){
          week = '';
        }
        if(weather.includes("天气状况")){
          weather = '';
        }
        $.ajax({
          type: "post",
          url: "http://127.0.0.1:8082/api/crawler/weather_status",
          cache: false,
          data: {
            publish_time : publish_time,
            week : week,
            weather : weather,
            city__name : city__name
          },
          success : function(res) {
            var result = res.results
            for (var i=0; i<result.length;i++){
              xValue.push(result[i].weather)
              yValue.push(parseInt(result[i].count))
            }
            initEcharts(xValue,yValue);
          }
        });
      });
      // 风向分析
      $("#windBtn").click(function() {
        $("#opDataxJobRowModal").modal('toggle');
        var publish_time = $("#publish_time").val();
        var week = $("#week option:selected").val();
        var weather = $("#weather option:selected").val();
        var city__name = $("#city__name").val();
        if(week.includes("全部星期")){
          week = '';
        }
        if(weather.includes("天气状况")){
          weather = '';
        }
        $.ajax({
          type: "post",
          url: "http://127.0.0.1:8082/api/crawler/wind_status",
          cache: false,
          data: {
            publish_time : publish_time,
            week : week,
            weather : weather,
            city__name : city__name
          },
          success : function(res) {
            var result = res.results
            for (var i=0; i<result.length;i++){
              xValue.push(result[i].wind_direction)
              yValue.push(parseInt(result[i].count))
            }
            initEcharts(xValue,yValue);
          }
        });
      });

      // 关闭模态框后状态
      $('#opDataxJobRowModal').on('hidden.bs.modal', function () {
          myChart.clear();
          myChart = '';
          xValue = [];
          yValue = [];
      })
    </script>
  </body>
</html>
